package fr.mbds.first.wallet.entity;

public class Converter {

	private static String getString(double d) {
		d = d * 10000;
		String s = "" + (int) d;
		int i = 12 - s.length();
		for (int ii = 0; ii < i; ii++) {
			s = "0" + s;
		}
		return s;
	}

	private static double getDouble(String s) {
		double d;
		s = s.substring(0, 8) + "." + s.subSequence(8, 12);
		d = Double.parseDouble(s);
		return d;
	}

	public static String getStringPin(double d, boolean action) {
		String str;
		if(action)
			str = "1" + getString(d) + "6301";
		else
			str = "0" + getString(d) + "6301";
		return str;
	}

	public static String getStringSuccess(double d, boolean action) {
		String str;
		if(action)
			str = "1" + getString(d) + "9000";
		else
			str = "0" + getString(d) + "9000";
		return str;
	}

	public static double getDoubleFromRequest(String s) {
		return getDouble(s.substring(1, s.length() - 4));
	}

}
